import { generateAvatar } from "@/utils/avatarGenerator";
import request from "@/utils/request";

// 用户注册
export const register = (data: { username: string; password: string }) => {
  return request.post<IResponse<{ user: User; token: string }>>(
    "/auth/register",
    data
  );
};

// 用户登录
export const login = (data: { username: string; password: string }) => {
  return request.post<IResponse<{ user: User; token: string }>>(
    "/auth/login",
    data
  );
};

// 获取当前用户信息
export const getCurrentUser = () => {
  return request.get<IResponse<{ user: User }>>("/auth/me");
};

// 根据ID获取用户信息
export const getUserById = (id: string) => {
  return request.get<IResponse<{ user: User }>>(`/users/${id}`);
};

// 生成用户头像
export const generateUserAvatar = (username: string, size: number = 100) => {
  return generateAvatar(username, { size });
};
